// index.js
// 获取应用实例
const app = getApp()
const common = require('../../utils/common.js');
const api = require('../../api/api.js');
Page({
  data: {
    show: false,
    shouquanShow: false,
    indicatorDots:true,
    swiper_imgList: [],
    taocan:[],
    user_id:wx.getStorageSync('user_id')
  },

  onShow(){
    this.get_indexInfo();
    this.setData({
      show:false,
      shouquanShow:false
    })
    var user_id=wx.getStorageSync('user_id')
    if(!user_id){
      this.setData({
        shouquanShow:true
      })

    }
  },

  to_detail(e) {
    console.log(e);
    wx.navigateTo({
      url: '/pages/goods-detail/goods-detail?id=' + e.currentTarget.dataset.id,
    })
  },
  canCel_order() {
    
    let that = this;
    let order_id = that.data.payorderid;
    common.request(api.orderClose,{order_id:order_id},'POST').then((res) => {
      console.log(res)
      if (res.status == 1) {
        wx.showToast({
          title: '取消成功',
          icon:'none'
        })
        that.setData({
          show: false
        })

      }else{

        wx.showToast({
          title: res.msg,
          icon:'none'
        })

      }
        
    })
  },
  quxiaoFnc() {
    this.setData({
      shouquanShow: false
    })
  },
  shouquan() {
    wx.navigateTo({
      url: '/pages/shouquan/shouquan',
    })
  },
  //立即支付
  payOrder(){
    wx.navigateTo({
      url: '/pages/order-confirm/order-confirm?order_id=' + this.data.payorderid,
    })
  },
  //首页信息
  get_indexInfo(){
    let that = this;
    common.request(api.get_indexInfo,{},'POST').then((res) => {
      console.log(res)
        that.setData({
          swiper_imgList : res.banner,
          taocan : res.taocan
        })


        if(res.order_id&&res.order_id!=0){
          this.setData({
            show:true,
            payorderid:res.order_id
          })
          console.log(this.data.payorderid)
        }
    })
  },
   /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})